package quickAdd.client;

import com.google.gwt.xml.client.XMLParser;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Document;
import com.google.gwt.user.client.ResponseTextHandler;

/**
 * Parse resonse text as XML, passing to handle() method.
 * Exceptions are logged.
 * 
 * Date: Mar 9, 2007 Time: 1:41:49 PM
 *
 * @author pat
 */
public abstract class XMLResponseHandler implements ResponseTextHandler
{
    public void onCompletion( String responseText )
    {
        try {
            Document doc = XMLParser.parse( responseText );
            Element element = doc.getDocumentElement();
            handle( element );
        } catch ( RuntimeException e ) {
            System.err.println("onCompletion Exception: "+e);
            QuickAdd.out( "onCompletion Exception: "+e);
            handleError( responseText );
        }
    }

    public void handleError( String responseText ) {
        QuickAdd.out( "xml parse error: " + responseText );
    }
    public abstract void handle( Element element );
}

